<?php
namespace app\index\controller;

class News extends Common
{
    public function index()
    {   $id=input('id');
    if(empty($id)){
        $articles=db('article')->order('time DESC')->paginate(20);
        $this->assign("catename","新闻资讯");
        $this->assign('cateid',1);
    }else{
       $articles=db('article')->where(array('cateid'=>$id))->order('time DESC')->paginate(20);  
       $catename=db('cate')->where(array('id'=>$id))->select();
       $this->assign("catename",$catename[0]['catename']);
       $this->assign('cateid',$id);
    }
        $this->assign('articles',$articles);


    

        return view();
    }

   

    public function article(){
      $id=input('id');
      $single=db('article')->where(array('id'=>$id))->find();
      $catetmp=db('cate')->where(array('id'=>$single['cateid']))->find();
        $this->assign('single',$single);
        $this->assign('catetmp',$catetmp);
        //print_r($cate);
        $res=db('article')->where(array('cateid'=>$single['cateid']))->order(' click DESC')->select();
        $this->assign('res',$res);
        $this->assign('resnum',count($res));
        //上下篇
        $f=db('article')->where("id < $id")->order("id DESC limit 1")->select();
       $this->assign("f",$f);
         $l=db('article')->where("id > $id")->order("id ASC limit 1")->select();
       $this->assign("l",$l);
        //上下篇
        return view();
    }
}
